package com.kis.controller.user

import com.alibaba.fastjson.JSON
import com.kis.model.ResponseData
import com.kis.model.user.User
import com.kis.service.user.UserClient
import io.swagger.annotations.Api
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController

/**
 * Created by wongloong on 16-12-7.
 */
@RestController
@RequestMapping("/api/user")
@Api(description = "用户相关操作")
class UserController {
    @Autowired
    lateinit private var userClient: UserClient

    @ApiOperation("添加用户")
    @ApiImplicitParams(
            ApiImplicitParam(name = "username", paramType = "query", dataType = "String", required = true, value = "用户登录名", defaultValue = "test"),
            ApiImplicitParam(name = "password", paramType = "query", dataType = "String", required = true, value = "用户登录密码", defaultValue = "test"),
            ApiImplicitParam(name = "realName", paramType = "query", dataType = "String", required = true, value = "用户真实姓名", defaultValue = "test")
    )
    @RequestMapping(method = arrayOf(RequestMethod.POST))
    fun User(user: User): ResponseData = userClient.saveOrUpdate(JSON.toJSONString(user))

}